package 数组.练习;

import javax.sound.midi.Soundbank;
import java.util.Scanner;

/**
 * 定义一个 Print 类
 * @author lanqiao
 */
public class Print {

    Scanner input = new Scanner(System.in);
    int m = 0 ;//行数
    int n = 0 ; //列数

    //当前正在打印的数字是： arr[row][column]
    int row = 0, column = 0;
    // 约定打印的方向
    int right = 0;
    int down = 1;
    int left = 2;
    int up = 3;
    int [][]arr  = null ;
    //当前正在打印的方向（从“右”开始）
    int direction = right;
    //当前正在打印第几圈
    int circle = 1;
    //当前正在打印第几个数字
    int count = 0;


    //输入行号、列号，并初始化二维数组
    public void input(){
        Scanner sc=new Scanner(System.in);
        System.out.println("行：");
        m=sc.nextInt();
        System.out.println("列：");
        n=sc.nextInt();
        arr=new int[m][n];
    }

    //填充二维数组
    public void fillArray(){
        for (int i = 1; i <= m*n; i++) {
            arr[row][column]=i;
            switch (direction) {
                case 0://right
                    if(column<n-circle){
                        column++;
                    }else{

                    }
                    break;
                case 1://down
                    break;
                case 2://left
                    break;
                case 3://up
                    break;
            }
        }
    }

    //打印
    public void print(){
        for (int i = 0; i < m; i++) {
            for (int j = 0; j < n; j++) {
                if (arr[i][j] < 10) {
                    System.out.print(arr[i][j] + " " + " ");
                } else {
                    System.out.print(arr[i][j] + " ");
                }
            }
            System.out.println();
        }
    }
}
